package actions;

import game.constants.ReferenceAction;
import game.constants.ReferenceSpecialFeature;
import interfaces.ActionInterface;
import interfaces.impl.Action;
import objects.SpetialFeature;
import universe.Universe;

public class ActionIncreaseLife extends Action{
	
	private double lifeToIncrease;

	@Override
	public ActionInterface cloneAction() {
		ActionIncreaseLife action = new ActionIncreaseLife();
		action.modifyAction(this);
		return action;
	}

	@Override
	public boolean processActionChild(Universe universe) {
		
		SpetialFeature currentLife = target.getFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_CURRENT_LIFE);
		SpetialFeature totalLife = target.getFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_LIFE);
		if(currentLife==null || totalLife == null){
			return false;
		}
		if(lifeToIncrease+currentLife.getValue()>=totalLife.getValue()){
			currentLife.setValue(totalLife.getValue());
			return true;
		}
		currentLife.setValue(currentLife.getValue()+lifeToIncrease);
		return true;
	}

	public double getLifeToIncrease() {
		return lifeToIncrease;
	}

	public void setLifeToIncrease(double lifeToIncrease) {
		this.lifeToIncrease = lifeToIncrease;
	}

	@Override
	public void initializeName() {
		name="increase life";
		
	}

	@Override
	public void initializeId() {
		id=ReferenceAction.ACTION_INCREASE_LIFE;
		
	}

	@Override
	public void modifyChild(ActionInterface action) {
		if (action instanceof ActionIncreaseLife){
			this.lifeToIncrease=((ActionIncreaseLife) action).lifeToIncrease;
		}
		
	}
	
	

}
